package demo01;

import java.sql.*;

/**
 * util 包下的工具类
*/
public class JDBCUtil {
    public static String DRIVERCLASS="com.mysql.jdbc.Driver";
    public static String URL="jdbc:mysql://localhost:3306/zyg_pm1";
    public static String USER="root";
    public static String PASSWORD="Fang060825";
    // 连接数据库
    public static Connection getConn() throws Exception {
        Class.forName(DRIVERCLASS);
        Connection conn = DriverManager.getConnection(URL, USER, PASSWORD);
        return conn;
    }
    //释放资源
    public static void close(ResultSet rs, Statement st, Connection conn) throws SQLException {
              if(rs!=null)
              {
                  conn.close();
              }
              if(st!=null)
              {
                  st.close();
              }
              if(conn!=null)
              {
                  conn.close();
              }
    }
    public static void close( Statement st, Connection conn) throws SQLException {
        if(st!=null)
        {
            st.close();
        }
        if(conn!=null)
        {
            conn.close();
        }
    }
}
